package com.example.customizeview;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;

public class SecondActivity extends Activity {
    private static final String TAG = "MainActivity";
    private LinearLayout ll;
    private WebView webView;
    View view;
    View view2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        //初始化WebView
        WebViewUtils.initWebView(this);
        ll = (LinearLayout) findViewById(R.id.ll);
        view = findViewById(R.id.view);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                webView = WebViewUtils.getWebView();
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                ll.addView(webView, lp);
                webView.setWebViewClient(new WebViewClient() {
                    @Override
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        view.loadUrl(url);
                        return true;
                    }
                });
                webView.loadUrl("http://www.baidu.com/");
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ll.removeView(webView);
    }
}
